package com.hisense.ovcloud.common3.kafka;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.boot.ssl.DefaultSslBundleRegistry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.kafka.core.reactive.ReactiveKafkaProducerTemplate;
import reactor.kafka.sender.SenderOptions;

@Configuration
@Slf4j
@Lazy
@ConditionalOnClass(KafkaAutoConfiguration.class)
public class ReactiveKafkaConfig {
    private final KafkaProperties properties;

    public ReactiveKafkaConfig(KafkaProperties properties) {
        this.properties = properties;
    }

    @Bean
    public ReactiveKafkaProducerTemplate<String, String> reactiveKafkaProducerTemplate() {
        return new ReactiveKafkaProducerTemplate<>(SenderOptions.create(properties.getProducer().buildProperties(new DefaultSslBundleRegistry())));
    }
}
